package controller;

import entity.Students;
import service.StudentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api/students")
public class StudentsController {

    @Autowired
    private StudentsService studentsService;

    @GetMapping("/{id}")
    public Students getById(@PathVariable Integer id) {
        return studentsService.getById(id);
    }

    @GetMapping("/all")
    public List<Students> getAll() {
        return studentsService.getAll();
    }

    @PostMapping
    public int create(@RequestBody Students obj) {
        return studentsService.create(obj);
    }

    @PutMapping
    public int update(@RequestBody Students obj) {
        return studentsService.update(obj);
    }

    @DeleteMapping("/{id}")
    public int delete(@PathVariable Integer id) {
        return studentsService.delete(id);
    }
}